package ee.roosideSoda.frontend;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ee.roosideSoda.GeneralConstants;
import ee.roosideSoda.backend.model.data.KaimasolevaYldkysimuseAndmed;
import ee.roosideSoda.backend.services.KaimasolevaYldkysimuseAndmedService;
import ee.roosideSoda.backend.services.implementations.KaimasolevaYldkysimuseAndmedServiceImpl;
import ee.roosideSoda.frontend.controller.menucontrollers.AdminInterfaceMenuController;
import ee.roosideSoda.frontend.controller.menucontrollers.GameInterfaceMenuController;
import ee.roosideSoda.frontend.controller.menucontrollers.MenuController;
import ee.roosideSoda.frontend.controller.menucontrollers.MenuControllerFactory;
import ee.roosideSoda.frontend.controller.menucontrollers.UuteTiimideLoomiseMenuController;
import ee.roosideSoda.frontend.view.ViewManager;

/**
 * Servlet implementation class GameInterface
 */
@WebServlet("/GameInterface")
public class GameInterface extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
    
    public GameInterface() 
    {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		request.setCharacterEncoding(GeneralConstants.ENCODING_ISO_8859_1);
		response.setContentType(GeneralConstants.CONTENT_TYPE_HTML_ISO_8859_1);
	
		try
		{
			ViewManager viewManager = new ViewManager();
			String view = "gameInterfaceLehekylg";
			ServletContext servletContext = getServletConfig().getServletContext();
			
			//--------Vaatame, kas on uued tiimid vaja luua---------
			KaimasolevaYldkysimuseAndmedService kaimasolevaYldkysimuseAndmedServiceImpl = new KaimasolevaYldkysimuseAndmedServiceImpl();
			KaimasolevaYldkysimuseAndmed kaimasolevaYldkysimuseAndmed = kaimasolevaYldkysimuseAndmedServiceImpl.saaKaimasolevaYldkysimuseAndmed();
			MenuControllerFactory menuControllerFactory  = new MenuControllerFactory();
			MenuController menuController = null;
			
			menuController = new GameInterfaceMenuController();
			view = menuController.service(request, response);
			viewManager.navigate(view, request, response, servletContext);	
			
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}
